<template>
    <div>
        <el-scrollbar class="template-scroll">
            <div v-for="template in templateList" :key="template.id" class="template-item"
                :class="[activeTemplate.id == template.id ? 'active' : '']" @click="selectTemplate(template)">
                <div class="template-name">{{ template.templateName }}</div>
                <div>
                    <el-button type="text" @click="showEditTemplateDialog(template)">编辑</el-button>
                    <el-button type="text" @click="deleteTemplate(template)">删除</el-button>
                </div>
            </div>
        </el-scrollbar>
    </div>
</template>

<script setup>

const props = defineProps({
  templateList: {
    type: Array,
    default: () => []
  },
  activeTemplate: {
    type: Object,
    default: () => ({id:''})
  },
})

const emit = defineEmits(['update:activeTemplate', 'deleteTemplate','selectTemplate']);
const showEditTemplateDialog = (template) => {
  emit('showEditTemplateDialog', template)
}
const deleteTemplate = (template) => {
  emit('deleteTemplate', template)
}

const selectTemplate = (template) => {
  emit('selectTemplate', template)
}

</script>

<style scoped lang="scss">
.template-scroll {
  height: 850px;
  overflow-y: auto;
}

.template-item {
  padding: 15px;
  margin-bottom: 10px;
  border-radius: 4px;
  cursor: pointer;
  background-color: #fff;
  border: 1px solid #ebeef5;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.template-item:hover {
  border-color: #409eff;
}

.template-item.active {
  border-color: #409eff;
  background-color: #ecf5ff;
}

.template-name {
  font-weight: bold;
  margin-bottom: 5px;
}
</style>